<?php

include "_connection.php";
$var = conectar();
session_start();
//session_destroy();

//Le data
$email = $_GET['email'];
$pass = $_GET['pass'];


if ($_SESSION["type_login"] == "admin" ) {
	$table = "administrators";
} else if ($_SESSION["type_login"] == "author" ) {
	$table = "authors";
} else if ($_SESSION["type_login"] == "editor" ) {
	$table = "editors";
} else if ($_SESSION["type_login"] == "reviser " ) {
	$table = "revisers";
} else {
	header('Location: /backend/');
}


$sql = "SELECT * FROM $table WHERE email='$email' AND pass='$pass'";
$res =mysql_query($sql);
$obj = mysql_fetch_object($res);


if (isset($obj->name)) {
	$_SESSION['id'] = $obj->id_author;
	$_SESSION['loged'] = true;
	$_SESSION['name'] = $obj->name;
}


if ($_SESSION['loged']) {
	if ($_SESSION["type_login"] == "admin" ) {
		header('Location: /backend/admin/');
	} else if ($_SESSION["type_login"] == "author" ) {
		header('Location: /backend/autor/');
	} else if ($_SESSION["type_login"] == "editor" ) {
		header('Location: /backend/editor/');
	} else if ($_SESSION["type_login"] == "reviser " ) {
		header('Location: /backend/revisor/');
	} 
} else {
	header('Location: /backend/');
}
?>